import * as _ from 'lodash';
import coordtransform from "coordtransform";
import moment from 'moment';
import request from '@/utils/request'
//点位类型
export const POINT_TYPE_ARRAY = [
    { label: '1', name: '感知', disabled: false, class: ''},
    { label: '2', name: '通信', disabled: true, class: ''}
]

//点位状态
export const POINT_STATUS_ARRAY = [
    // { label: '0', name: '-', class: '' },
    { label: '1', name: '在线', class: 'point-state online' },
    { label: '2', name: '离线', class: 'point-state offline' }
]

//设备状态
export const DEVICE_STATUS_ARRAY = [
    // { label: '0', name: '-', class: '' },
    { label: '1', name: '在线', class: 'point-state online' },
    { label: '2', name: '离线', class: 'point-state offline' }
]

//最新测试目标
export const POINT_TEST_TARGET = [
    { label: '0', name: '未知', class: '' },
    { label: '1', name: '机动车', class: '' },
    { label: '2', name: '行人', class: '' },
    { label: '3', name: '非机动车', class: '' }
]

//最新测试目标
export const TASK_DEVICE_TYPE = [
    { label: '1', name: '路侧', class: '' },
    { label: '2', name: '机动车', class: '' },
]

//监测风险等级
export const RISK_LEVEL = [
    { label: '1', name: '正常', class: 'point-state online' },
    { label: '2', name: '告警', class: 'point-state offline' }
]

//任务状态
export const TASK_STATUS = [
    { label: '1', name: '待测试', class: 'point-state warning' },
    { label: '2', name: '测试中', class: 'point-state online' },
    { label: '3', name: '已完成', class: '' },
    { label: '4', name: '待分析', class: '' },
    { label: '5', name: '分析失败', class: '' }
]

//任务测试评级
export const QUALITY_IN_TASK = [
    { label: '0', name: '良好', class: 'dict-status nice' },
    { label: '1', name: '合格', class: 'dict-status normal' },
    { label: '2', name: '不合格', class: 'dict-status bad' },
    { label: '-1', name: '无效', class: '' },
]

//测试评级
export const TEST_RESULT_LEVEL = [
    { label: '0', name: '良好', class: 'dict-status nice' },
    { label: '1', name: '合格', class: 'dict-status normal' },
    { label: '2', name: '不合格', class: 'dict-status bad' },
    { label: '-1', name: '-', class: '' },
]

//测试评级
export const DB_TEST_RESULT_LEVEL = [
    { label: '0', name: '良好', class: 'status-tap green' },
    { label: '1', name: '合格', class: 'status-tap orange' },
    { label: '2', name: '不合格', class: 'status-tap red' },
    { label: '-1', name: '-', class: '' },
]

//测试指标indicator
export const INDICATOR_TYPE_LIST = [
    { label: '1', name: '定位精度' },
    { label: '2', name: '速度精度' },
    { label: '3', name: '航向精度' },
    { label: '4', name: '定位方差' },
    { label: '5', name: '速度方差' },
    { label: '6', name: '航向方差' }
]

//权限菜单类型
export const MENU_TYPE = [
    { label: 'M', name: '目录'},
    { label: 'C', name: '菜单'},
    { label: 'F', name: '按钮'},
]

//权限菜单筛选条件
export const MENU_FILTER_TYPE = [
    { value: '', label: '全部'},
    { value: 'M', label: '目录'},
    { value: 'C', label: '菜单'},
    { value: 'F', label: '按钮'},
]

//是否隐藏
export const VISIBLE_OPTION = [
    { value: '0', label: '显示'},
    { value: '1', label: '隐藏'},
]

//路口形状
export const ROAD_SHAPE_TYPE = [
    { label: 1, name: '一字型'},
    { label: 2, name: '十字型'},
    { label: 3, name: 'X形'},
    { label: 4, name: 'T形'},
    { label: 5, name: 'Y形'},
    { label: 6, name: '环形'},
]

//路口类型
export const ROAD_TYPE = [
    { label: 1, name: '路口'},
    { label: 2, name: '路段'}
]

//杆件类型
export const ROD_TYPE = [
    { label: 1, name: 'F型'},
    { label: 2, name: 'L型'},
    { label: 3, name: 'T型'},
    { label: 4, name: '龙门架'}
]

//路侧设备类型
export const ROAD_DEVICE_TYPE = [
    { label: 1, name: 'RUS'},
    { label: 2, name: 'RCU'},
    { label: 3, name: '毫米波雷达'},
    { label: 4, name: '激光雷达'},
    { label: 5, name: '摄像机'}
]

// 点击地图类型
export const MAP_CLICK_TYPE = {
    getPoint: 'GET_POINT',
    drawLine: 'DRAW_LINE',
}

// 表单创建状态
export const FORM_STATE = {
    create: 'CREATE',
    edit: 'EDIT',
    view: 'VIEW',
    bind: 'BIND'
}

//告警弹窗类型
export const DIALOG_TYPE = {
    alert: 'ALERT',
    order: 'ORDER'
}

//告警类型
export const ALERT_TYPE_LIST = [
    // { label: 0, name: '巡检任务'},
    { label: 1, name: '轨迹合理性'},
    { label: 2, name: '轨迹波动性'},
    { label: 3, name: '轨迹交互性'},
    { label: 4, name: '丢包率'},
    { label: 5, name: '时延'},
    { label: 6, name: '时间间隔'},
]

//告警状态
export const ALERT_STATUS_LIST = [
    { label: 1, name: '未处理'},
    { label: 2, name: '处理中'},
    { label: 3, name: '已处理'},
    { label: 4, name: '已过期'}
]

//工单状态
export const ORDER_STATUS_LIST = [
    { label: 1, name: '待接收'},
    { label: 2, name: '处理中'},
    { label: 3, name: '已完成'},
]


//风险等级
export const DATA_RISK_LEVEL = [
    { label: 0, name: '正常', class: 'point-state online' },
    { label: 1, name: '低风险', class: 'point-state warning' },
    { label: 2, name: '高风险', class: 'point-state error' },
    { label: -1, name: '无', class: '' },
]

//告警来源
export const ORDER_SOURCE = [
    { label: '', name: '全部'},
    { label: 1, name: '质量监测'},
    { label: 2, name: '巡检测试'}
]


export const getLabelInfoByValue = (value, type) => {
    const valueCopy = _.cloneDeep((value || value === 0 ? value : '') + '');
    let array = [];
    switch(type) {
        case 'pointType':
            array = _.cloneDeep(POINT_TYPE_ARRAY);
            break;
        case 'pointState':
            array = _.cloneDeep(POINT_STATUS_ARRAY);
            break;
        case 'deviceStatus':
            array = _.cloneDeep(DEVICE_STATUS_ARRAY);
            break;
        case 'testTarget': case 'taskTarget':
            array = _.cloneDeep(POINT_TEST_TARGET);
            break;
        case 'riskLevel':
            array = _.cloneDeep(DATA_RISK_LEVEL);
            break;
        case 'taskStatus':
            array = _.cloneDeep(TASK_STATUS);
            break;
        case 'qualityInTask': 
            array = _.cloneDeep(QUALITY_IN_TASK);
            break;
        case 'totalQuality': case 'testRate':
            array = _.cloneDeep(TEST_RESULT_LEVEL);
            break;
        case 'db_totalQuality':
            array = _.cloneDeep(DB_TEST_RESULT_LEVEL);
            break;
        case 'indicator':
            array = _.cloneDeep(INDICATOR_TYPE_LIST);
            break;
        case 'menuType':
            array = _.cloneDeep(MENU_TYPE);
            break;
        case 'taskDeviceId':
            array = _.cloneDeep(TASK_DEVICE_TYPE);
            break;
        case 'roadShapeType':
            array = _.cloneDeep(ROAD_SHAPE_TYPE);
            break;
        case 'roadType':
            array = _.cloneDeep(ROAD_TYPE);
            break;
        case 'rodType':
            array = _.cloneDeep(ROD_TYPE);
            break;
        case 'roadDeviceType':
            array = _.cloneDeep(ROAD_DEVICE_TYPE);
            break;
        case 'alertType':
            array = _.cloneDeep(ALERT_TYPE_LIST);
            break;
        case 'alertStatus':
            array = _.cloneDeep(ALERT_STATUS_LIST);
            break;
        case 'orderStatus':
            array = _.cloneDeep(ORDER_STATUS_LIST);
            break;
        case 'dataRiskLevel':
            array = _.cloneDeep(DATA_RISK_LEVEL);
            break;
        case 'sourceType':
            array = _.cloneDeep(ORDER_SOURCE);
            break;
        case 'pointPosition':
            const posTrans = _.map(valueCopy.split(','), item => {
                return _.round(item, 8);
            });
            return {
                label: posTrans.join(',')
            }
        case 'perceptionRange':
            const rangeArr = _.map(valueCopy.split(';'), item => {
                const pointArr = _.map(item.split(','), point => {
                    return _.round(point, 8)  
                })
                return pointArr.join(',')
            })
            const str = rangeArr.join(';<br/>')
            return {
                label: str
            }
    }
    if(array.length === 0 ) {
        return { label: valueCopy, class: '' };
    } else if (_.isNil(valueCopy) || !valueCopy) {
        return { label: '-', class: '' };
    } else {
        const result = _.find(array, item => item.label + '' === valueCopy);
        return {
            label: result ? result.name : (!_.isNil(value) ? valueCopy : '-'),
            class: result ? result.class : ''
        };
    }
}

//文本添加换行\n
export const addLineBreak = (value) => {
    if(!value) return value;
    const result = _.map(value.split(';'), item => {
        return item + '\n'
    })
    return result.join(';');
}

//文本移除换行\n
export const removeLineBreak = (value) => {
    if(!value) return value;
    return value.split('\n').join('');
}

export const INIT_CHART_OPTION = {
    grid: {
        left: 0, // 调整绘图区域靠左显示
        top:50,
        right: 0,
        bottom:0,
        containLabel: true
    },
    legend: {
        bottom:'30px',
        //图例距离饼图的距离
        itemGap: 10,
        itemWidth:10,
        itemHeight:10,
        data: [
            // '待下发','处置中','已完成'
            {
                name: '良好',
                textStyle: { color: '#68c23b' }
            },
            {
                name: '合格',
                textStyle: { color: '#e6a23c' }
            },
            {
                name: '不合格',
                textStyle: { color: '#f56c6d' }
            },
            {
                name: '无效',
                textStyle: { color: '#b2b3b8' }
            },
        ],
        textStyle: {
            color:'#C8D0FF',
            fontSize:14,
        },
    },
    series: [
        {
            type: 'pie',
            radius: ['30%', '45%'],
            center: ['50%', '50%'], //饼图位置
            // stillShowZeroSum: true,
            color: ['#68c23b', '#e6a23c', '#f56c6d','#b2b3b8'],
            width: 380,
            data: [
                { value: 0, name: '良好' },
                { value: 0, name: '合格' },
                { value: 0, name: '不合格' },
                { value: 0, name: '无效' },
            ],
            itemStyle: {
                borderColor: '#ffffff',
                borderWidth: 2
            },
            emphasis: {
                label: {
                    show: true,
                }
            },
            label: {
                show: false,
				alignTo: 'labelLine',
				minMargin: 4, //label外边距
				lineHeight: 18, //字的行高
				distanceToLabelLine: 0, //字到线的距离				
                borderColor: 'inherit',
				borderWidth: 0,
				padding: [0, 0, 0, 0],
				width: 0,
				overflow: 'none',
                color: 'inherit',
				rich: {
					name: {
						fontSize: 10,
                        color: '#ffffff',
                        padding: 6,
                        backgroundColor: 'inherit',
                        width: 60
					},
                    percent: {
                        fontSize: 10,
                        color: '#ffffff',
                        padding: [0, 6, 6, 6],
                        width: '50px',
                        backgroundColor: 'inherit',
                        width: 60
                    }
				},
                formatter: `{name|{b}数:{c}个}\n{percent|占比{d}%}`,
			},
            //蜘蛛标签
			labelLayout: (params) => {
				return {
                    hideOverlap: true,
				    width: 0,
                    align: params.align
                }
			},
			labelLine: {
				maxSurfaceAngle: 90, //最大倾斜角度
				minTurnAngle: 90,
				smooth: 0.03,
				lineStyle: {
					width: 2,
					opacity: 0.6
				},
			},
        }
    ]
}

export const INIT_LINE_OPTION = {
    color: ['#1364FF'],
    grid: {
        left: '5%', // 调整绘图区域靠左显示
        top:'100px',
        right: '8%',
        left: '100px',
        bottom: '20%',
        containLabel: true
    },
    tooltip: {
        trigger: 'axis',
        backgroundColor: 'rgba(49,57,119,0.8)',
        borderColor: 'transparent',
        padding: [15, 20],
        axisPointer: {
            type: 'line'
        },
        textStyle: {
            color: '#ffffff'
        }
    },
    xAxis: [
        {
            type: 'category',
            axisTick: {
                alignWithLabel: true
            },
            data: [],
            axisLabel: {
                show: true,
                formatter: (value) => {
                    const valueArr = value?.split(',');
                    const time = moment(valueArr[0]).format('HH:mm:ss');
                    return `{a|${valueArr[1] ? `${valueArr[1]}\n` : ''}${time}}`
                },
                rich: {
                    a: {
                        textAlign: 'center',
                    }
                }
            }
        }
    ],
    yAxis: [
        {
            type: 'value',
            name: '',
            position: 'left',
            alignTicks: true,
            splitNumber: 5,
            axisLine: {
                show: false,
            },
            axisLabel: {
                formatter: '{value}'
            },
            nameTextStyle: {
                color: '#323233',
                fontWeight: 700,
                fontSize: 14,
                align: 'right'
            }
        }
    ],
    series: [
        {
            name: '航向角(deg)',
            type: 'line',
            smooth: false,
            areaStyle: {
                color: 'rgba(149,168,255,0.4)'
            },
            data: []
        }
    ]
}

export const tooltipModule = {
    trigger: 'axis',
    backgroundColor: 'rgba(49,57,119,0.8)',
    borderColor: 'transparent',
    padding: [15, 20],
    formatter: function (params) {
        const taskCode = params[0].axisValue ?  params[0].axisValue?.split(',')[1] : '-';
        const time = params[0].axisValue ? params[0].axisValue?.split(',')[0] : '-';
        let res = `<div style="width: 200px; margin-bottom: 10px">
            <div style="font-size: 18px; color: white;">${taskCode}</div>
            <div style="font-size: 12px; color: #C5C9DE; margin-top: 3px">${time}</div>
        </div>`

        _.forEach(params, (item, index) => {
            res += `<div style="font-size: 14px; display: flex; justify-content: space-between; align-items: center">
            <div style="color: #F1F3F9; display: inline-flex; align-items: center">
                <i style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${item.color};"></i>
                <span>${item.seriesName}</span>
            </div>
            <div>${_.isObject(item.data) ? item.data.value : item.data}</div>
            </div>`;
        })
        return res;
    },
    axisPointer: {
        type: 'line'
    },
    textStyle: {
        color: '#ffffff'
    }
}

export const dataZoomModule = [
    // {
    //     start:0,//默认为0
    //     end: 100-1500/31,//默认为100
    //     type: 'slider',
    //     show: true,
    //     xAxisIndex: [0],
    //     handleSize: 0,//滑动条的 左右2个滑动条的大小
    //     height: 10,//组件高度
    //     left: '10%', //左边的距离
    //     right: '5%',//右边的距离
    //     bottom: '10%',//下边的距离
    //     borderColor: "#000",
    //     fillerColor: '#DFE5F3',
    //     borderRadius:5,
    //     backgroundColor: '#F6F8FC',//两边未选中的滑动条区域的颜色
    //     showDataShadow: false,//是否显示数据阴影 默认auto
    //     showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
    //     realtime:true, //是否实时更新
    //     filterMode: 'filter',
    // },
    //1.横向使用滚动条
    {
        type: 'slider',//有单独的滑动条，用户在滑动条上进行缩放或漫游。inside是直接可以是在内部拖动显示
        show: true,//是否显示 组件。如果设置为 false，不会显示，但是数据过滤的功能还存在。
        start: 0,//数据窗口范围的起始百分比0-100
        end: 100,//数据窗口范围的结束百分比0-100
        xAxisIndex: [0],// 此处表示控制第一个xAxis，设置 dataZoom-slider 组件控制的 x轴 可是已数组[0,2]表示控制第一，三个；xAxisIndex: 2 ，表示控制第二个。yAxisIndex属性同理
        bottom:'8%', //距离底部的距离
        labelFormatter: function (value) {
            // console.log(value, '<==========value')
            // return 'aaa' + value + 'bbb';
        }
    },
    //2.在内部可以横向拖动
    {
        type: 'inside',// 内置于坐标系中
        start: 0,
        end: 30,
        xAxisIndex: [0]
    }
]

export const titleModule = {
    show: true,
    text: 'title',
    textStyle: {
        color: '#323233',
        fontSize: 14,
        fontWeight: 700
    },
    textAlign: 'center',
    left: 'center',
    top: 30
}

export const legendModule = {
    bottom:'30px',
    itemGap: 10,
    itemWidth:10,
    itemHeight:10,
    data: [
        {
            name: '良好',
            textStyle: { color: '#68c23b' }
        },
        {
            name: '合格',
            textStyle: { color: '#e6a23c' }
        },
        {
            name: '不合格',
            textStyle: { color: '#f56c6d' }
        },
        {
            name: '无效',
            textStyle: { color: '#b2b3b8' }
        },
    ],
    textStyle: {
        color:'#C8D0FF',
        fontSize:14,
    },
}

export const visualMapModule = {
    top: 10,
    right: 10,
    pieces: [
      {
        gt: 0,
        lte: 0.5,
        color: '#00D4B4'
      },
      {
        gt: 0.6,
        lte: 1.5,
        color: '#FBAA35'
      },
      {
        gt: 1.6,
        lte: 3,
        color: '#F92356'
      }
    ],
    outOfRange: {
      color: '#999'
    }
}

export const getInitYAxis = ({
    name,
    type,
    labelFormat
}) => {
    return {
        type: type ? type : 'value',
        name: name ? name : 'y轴',
        position: 'left',
        alignTicks: true,
        splitNumber: 5,
        axisLine: {
            show: false,
        },
        axisLabel: {
            formatter: labelFormat ? labelFormat : '{value}'
        },
        nameTextStyle: {
            color: '#323233',
            fontWeight: 700,
            fontSize: 14,
            align: 'right'
        }
    }
}

//计算两个经纬度的角度
export const calculateAngle = (a, b) => { //a起点，b终点
    const aLon = a && a[0] ? a[0] : '';
    const aLat = a && a[1] ? a[1] : '';
    const bLon = b && b[0] ? b[0] : '';
    const bLat = b && b[1] ? b[1] : '';
    if(!aLon || !aLat || !bLon || !bLat) return;
    if(aLon === bLon) {
        if (aLat === bLat) {
            return;
        } else {
            return bLat > aLat ? 0 : 180;
        }
    } else {
        if (aLat === bLat) {
            return bLon > aLon ? 90 : -90;
        } else {
            const lonDistance = bLon - aLon;
            const latDistance = bLat - aLat;
            const pointDistance = Math.sqrt(Math.pow(lonDistance, 2) + Math.pow(latDistance, 2));
            const cosValue = lonDistance / pointDistance;
            const radian = Math.acos(cosValue);
            const angleValue = radian * 180 / Math.PI;
            if (angleValue < 90) {
                return latDistance > 0 ? 90 - angleValue : 90 + angleValue;
            } else {
                return latDistance > 0 ? 90 - angleValue : angleValue - 270;
            }
        }
    }
}


//wgs坐标转
export const wgs84ToGcj02 = (lng, lat) => {
    const gcj02Coords = coordtransform.wgs84togcj02(lng, lat);
    return gcj02Coords;
}

export const gcj02toWgs84 = (lng, lat) => {
    const gcj02Coords = coordtransform.gcj02towgs84(lng, lat);
    return gcj02Coords;
}

export const getContentValue = (point) => {
    return `<div class='marker-hover-container'>
        <i class="indicator"></i>
        <div class='header'>
            <div class='point-name'>${point?.pointName}</div>
            <div class='in-dialog ${getLabelInfoByValue(point?.pointState, 'pointState').class}'>
                ${getLabelInfoByValue(point?.pointState, 'pointState').label}
            </div>
        </div>    
        <div class="info-item">
            <div class="label">点位类型</div>
            <div class="value">${getLabelInfoByValue(point?.pointType, 'pointType').label}</div>
        </div>
        <div class="info-item">
            <div class="label">点位位置</div>
            <div class="value">
                ${point && point.pointAddress ? point.pointAddress : '-'}
            </div>
        </div>
        <div class="gray-box">
            <div class="item">
                <div class="label">最新测试评级</div>
                <div class="value ${getLabelInfoByValue(point?.totalQuality, 'totalQuality').class}">
                    ${getLabelInfoByValue(point?.totalQuality, 'totalQuality').label}    
                </div>
            </div>    
            <div class="item">
                <div class="label">监测风险等级</div>
                <div class="value ${getLabelInfoByValue(point?.quality, 'riskLevel').class}">
                    ${getLabelInfoByValue(point?.quality, 'riskLevel').label}  
                </div>
            </div>    
        </div>
    </div>`
}

export const getRoadMarkerContent = (road) => {
    return `<div class='road-hover-container'>
        <i class="indicator"></i>
        <div class='header'>
            <div class='point-name'>${road?.name}</div>
        </div>    
        <div class="info-item">
            <div class="label">路口类型</div>
            <div class="value">
                ${getLabelInfoByValue(road?.type, 'roadType').label}
            </div>
        </div>
        <div class="info-item">
            <div class="label">地理位置</div>
            <div class="value" title=${road && road.address ? road.address : '-'}>
                ${road && road.address ? road.address : '-'}
            </div>
        </div>
        <div class="info-item">
            <div class="label width-100">路口/路段形状</div>
            <div class="value">
                ${getLabelInfoByValue(road?.shapeType, 'roadShapeType').label}
            </div>
        </div>
    </div>`
}


//全屏加载
export const fullLoadingOption = {
    lock: true,
    text: '正在处理中，请稍后...',
    spinner: 'el-icon-loading',
    background: 'rgba(255, 255, 255, 0.7)',
    customClass: 'custom-loading'
}

//默认时间范围选择
export const DEFAULT_TIME_RANGE = ['00:00:00', '23:59:59']


//定位合格阈值范围确定
export const POSITION_ERROR_RANGE = [1, 2];
//速度精度合格阈值范围
export const SPEED_ERROR_RANGE = [2, 5];
//航向精度合格阈值范围
export const HEADING_ERROR_RANGE = [3, 10];
//定位合格阈值范围确定
export const POSITION_VAR_RANGE = [0, 10];
//速度精度合格阈值范围
export const SPEED_VAR_RANGE = [0, 10];
//航向精度合格阈值范围
export const HEADING_VAR_RANGE = [0, 10];

export const chargeErrorStandard = (value, type, range) => {
    let classValue = '', result = true, rangeResult = [];
    switch(type) {
        case 'positionErrorMean': //定位误差值
            rangeResult = range && range.positionErrorRange ? range.positionErrorRange : POSITION_ERROR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        case 'speedErrorMean': //速度误差值
            rangeResult = range && range.speedErrorRange ? range.speedErrorRange : SPEED_ERROR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        case 'headingErrorMean': //航向误差值
            rangeResult = range && range.headingErrorRange ? range.headingErrorRange : HEADING_ERROR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        case 'positionErrorVar': //定位方差值
            rangeResult = range && range.positionVarRange ? range.positionVarRange : POSITION_VAR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        case 'speedErrorVar': //速度方差值
            rangeResult = range && range.speedVarRange ? range.speedVarRange : SPEED_VAR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        case 'headingErrorVar': //航向方差值
            rangeResult = range && range.headingVarRange ? range.headingVarRange : HEADING_VAR_RANGE;
            result = value >= rangeResult[0] && value <= rangeResult[1];
            break;
        default:
            result = true
    }
    classValue = (result || (value + '') === '-1') ? 'normal' : 'error';
    return classValue;
}

export const formatNumberToLine = (value) => {
    let valueCopy = _.cloneDeep(value + '');
    return (valueCopy === '-1' || !valueCopy || _.isNil(value)) ? '-' : valueCopy;
}


export const getAdviceByPointInfo = (point) => {
    let result = [];
    if(
        !(
            point.positionErrorMean >= POSITION_ERROR_RANGE[0] && 
            point.positionErrorMean <= POSITION_ERROR_RANGE[1]
        )
    ) {
        result.push(`定位精度误差(m)为${point.positionErrorMean}（正常阈值为1-2），传感器标定可能存在精度下降`);
    }

    if(
        !(
            point.speedErrorMean >= SPEED_ERROR_RANGE[0] && 
            point.speedErrorMean <= SPEED_ERROR_RANGE[1]
        )
    ) {
        result.push(`速度精度误差(m/s)为${point.speedErrorMean}（正常阈值为2-5），毫米波雷达可能存在精度下降`);
    }

    if(
        !(
            point.headingErrorMean >= HEADING_ERROR_RANGE[0] && 
            point.headingErrorMean <= HEADING_ERROR_RANGE[1]
        )
    ) {
        result.push(`航向精度误差(deg)为${point.headingErrorMean}（正常阈值为3-10）`);
    }

    return result.join('；');
}

export const formatEmptyValue = (value) => {
    if(value === '-1' || value === -1 || (!value && value !== 0)) {
        return '-';
    }
    return value;
}


export const longitudeReg = /^(\-|\+)?(((\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,14})|(\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,14}|180)$/;
// export const latitudeReg = /^[-+]?((180(\\.\\d{1,8})?)|((1[0-7]|[1-9]?\\d)(\\.\\d{1,8})?))$/;

export const latitudeReg = /^(\-|\+)?([0-8]?\d{1}\.\d{0,14}|90\.0{0,14}|[0-8]?\d{1}|90)$/;


//根据经纬度获取地址名称

export const getAddressByLocation = (longitude, latitude) => {
    request({
        url: 'https://restapi.amap.com/v3/geocode/regeo',
        method: 'get',
        data
    })
    let geocoder = new AMap.Geocoder({
        radius: 1000,
        extensions: 'all'
    });
       
    geocoder.getAddress([longitude, latitude], (status, result) => {
        if (status === 'complete' && result.info === 'OK') {
            resolve(result);
        } else {
            reject(result);
        }
    })
}

//菜单的权限字符串
export const authKeyList = {
    superAdmin: "*:*:*",
    //测试点位
    addPoint: 'patrolTest:pointManage:add',
    editPoint: 'patrolTest:pointManage:edit',
    viewPoint: 'patrolTest:pointManage:view',
    deletePoint: 'patrolTest:pointManage:delete',
    //测试任务
    addTask: 'patrolTest:taskManage:add',
    deleteTask: 'patrolTest:taskManage:delete',
    editTask: 'patrolTest:taskManage:edit',
    viewTask: 'patrolTest:taskManage:view',
    //测试数据对比
    //数据质量监测

    //组织管理
    addOrganization: 'system:orgManage:add',
    editOrganization: 'system:orgManage:edit',
    deleteOrganization: 'system:orgManage:delete',
    viewOrganization: 'system:orgManage:view',
    //菜单管理
    addMenu: 'system:menuManage:add',
    editMenu: 'system:menuManage:edit',
    deleteMenu: 'system:menuManage:delete',
    viewMenu: 'system:menuManage:view',
    //角色管理
    addRole: 'system:roleManage:add',
    editRole: 'system:roleManage:edit',
    deleteRole: 'system:roleManage:delete',
    viewRole: 'system:roleManage:view',
    configAuth: 'system:roleManage:configAuth',
    //账户管理
    addAccount: 'system:accountManage:add',
    editAccount: 'system:accountManage:edit',
    deleteAccount: 'system:accountManage:delete',
    viewAccount: 'system:accountManage:view',
    configRole: 'system:accountManage:configRole',
    suspendRole: 'system:accountManage:suspendRole',
    
    //路口管理
    addRoad: 'device:roadManage:add',
    editRoad: 'device:roadManage:edit',
    deleteRoad: 'device:roadManage:delete',
    viewRoad: 'device:roadManage:view',
    //杆件管理
    addPole: 'device:poleManage:add',
    editPole: 'device:poleManage:edit',
    deletePole: 'device:poleManage:delete',
    viewPole: 'device:poleManage:view',
    linkRoad: 'device:poleManage:linkRoad',
    //路测设备管理
    addRoadDevice: 'device:roadDeviceManage:add',
    editRoadDevice: 'device:roadDeviceManage:edit',
    deleteRoadDevice: 'device:roadDeviceManage:delete',
    viewRoadDevice: 'device:roadDeviceManage:view',
    linkPole: 'device:roadDeviceManage:linkPole',
    //测试设备管理
    addTestDevice: 'device:testDeviceManage:add',
    editTestDevice: 'device:testDeviceManage:edit',
    deleteTestDevice: 'device:testDeviceManage:delete',
    viewTestDevice: 'device:testDeviceManage:view',

    //故障告警
    viewAlarm: 'devops:alarmManage:view',
    deleteAlarm: 'devops:alarmManage:delete',
    transformAlarm: 'devops:alarmManage:transform',
    //维修工单
    viewOrder: 'devops:orderManage:view',
    deleteOrder: 'devops:orderManage:delete',
    //文件下载中心
    downloadFile: 'devops:fileManage:view',
    deleteFile: 'devops:fileManage:delete',
    //测试指标
    addTestIndicator: 'devops:testIndicatorManage:add',
    editTestIndicator: 'devops:testIndicatorManage:edit',
    deleteTestIndicator: 'devops:testIndicatorManage:delete',
}